package dnl.toolbox.time;

import java.util.Date;

/**
 * Encapsulates a time range.
 * 
 * @author Daniel Orr
 * 
 */
public class TimeRange {

	private Date startTime;
	private Date endTime;

	public TimeRange(Date startTime, Date endTime) {
		super();
		this.startTime = startTime;
		this.endTime = endTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	/**
	 * Checks if the given date occured after startTime and before endTime (non
	 * inclusive for both).
	 * 
	 * @param date
	 * @return
	 */
	public boolean contains(Date date) {
		return startTime.before(date) && endTime.after(date);
	}

	@Override
	public String toString() {
		return "TimeRange [startTime=" + startTime + ", endTime=" + endTime + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
		result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TimeRange other = (TimeRange) obj;
		if (endTime == null) {
			if (other.endTime != null)
				return false;
		} else if (!endTime.equals(other.endTime))
			return false;
		if (startTime == null) {
			if (other.startTime != null)
				return false;
		} else if (!startTime.equals(other.startTime))
			return false;
		return true;
	}

}
